<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <!-- 引入 ECharts 文件 -->
    <script src="./echarts.min.js"></script>
    <script src="./common.js"></script>
    <script src="./bar.js"></script>
    <script src="./line.js"></script>
    <script src="./pie.js"></script>
    <script src="./demo_data.js"></script>
    <style type="text/css">
        html,
        body {
            width: 100%;
            height: 100%;
        }

        * {
            margin: 0;
        }

    </style>
</head>

<body>
<!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->

<!-- 这个是测试的 有背景色 测试完记得注释掉 -->
<!-- <div id="chart" style="width:500px;height:400px;background-color: #222427;"></div> -->

<!-- 正式使用 -->
<div id="chart" style="height:100%;"></div>

<script type="text/javascript">
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('chart'))

        // 测试图表
        // var option = xgmLabelPie(xgmLabelPieDemoData())
        // var option = feesBar(grossProfitsBarDemoData())
        // var option = xgmThreePie(xgmThreePieDemoData())
         var option = bar(demoData30(),'#000')
         option && myChart.setOption(option,true)

        // Android传入图表数据
        function setData(source, dataJson,textColor) {
            try {
                console.log("设置图表数据：\n" + source + "," + dataJson + "\n" + typeof (dataJson));
                var datasetSource = JSON.parse(dataJson)
                console.log("解析图表数据：\n" + datasetSource + "\n" + typeof (dataJson));

                var option = optionFromSourceType(source, datasetSource,textColor)
                option && myChart.setOption(option, true)

            } catch (error) {
                console.log("图表加载失败: " + error)
            }
        }

        // 根据不同来源类型 获取对应的option数据
        function optionFromSourceType(source, dataJson,textColor) {
            if (source == "Bar") {
                return bar(dataJson,textColor)
            }if (source == "StickBar") {
                return stickBar(dataJson,textColor)
            } else if (source == "Line") {
                return line(dataJson,textColor)
            } else if (source == "StackLine") {
                return stackLine(dataJson,textColor)
            }  else if (source == "FillLine") {
                return fillLine(dataJson,textColor)
            }  else if (source == "Pie") {
                return pie(dataJson)
            }  else if (source == "LabelPie") {
                return labelPie(dataJson,textColor)
            }
        }


</script>
</body>

</html>